﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAO;
using DataAccess;
using System.Data;
namespace BUL
{
    public class DrugBUL
    {
        ConnectDatabase cd = new ConnectDatabase();
        public DataTable load() {
            String sql = "select idDrug as 'Mã thuốc',name as 'Tên thuốc',desription as 'Mô tả',unit as 'Đơn vị',amount as 'Số lượng' from drug";
            return cd.ExcuteQuery(sql);
        }
        public Boolean insert(DrugDAO p) { 
            String sql = @"insert into drug (name,desription, unit,amount) values(@name,@description,@unit,@amount)";
            int count = 4;
            String[] name = new String[count];
            object[] value = new object[count];
            name[0] = "@name";
            name[1] = "@description";
            name[2] = "@unit";
            name[3] = "@amount";
            value[0] = p.Name;
            value[1] = p.Desription;
            value[2] = p.Unit;
            value[3] = p.Amount;
            return cd.ExcuteNonQuery(sql, name, value, count);
        }
        public Boolean update(DrugDAO p)
        {
            String sql = @"update drug set name=@name, desription=@description, unit=@unit,amount=@amount where idDrug=@id";
            int count = 5;
            String[] name = new String[count];
            object[] value = new object[count];
            name[0] = "@name";
            name[1] = "@description";
            name[2] = "@unit";
            name[3] = "@amount";
            name[4] = "@id";
            value[0] = p.Name;
            value[1] = p.Desription;
            value[2] = p.Unit;
            value[3] = p.Amount;
            value[4] = p.IdDrug;
            return cd.ExcuteNonQuery(sql, name, value, count);
        }
        public Boolean delete(String id)
        {
            String sql = @"delete from drug where idDrug = '" + id + "'";
            return cd.ExcuteNonQuery(sql);
        }

    }
}
